package com.obas.business.topo {

//	import com.pktech.topo.lib.events.NetworkEvent;
//	import com.pktech.widgets.controls.Menu;
//	import com.pktech.widgets.controls.menu.MenuItem;
//	import com.pktech.widgets.events.AdvancedMouseEvent;
	
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	import mx.core.Container;
	import mx.events.MenuEvent;
	
	import twaver.Element;
	import twaver.ElementBox;
	import twaver.network.Network;
	
	public class BaseNetwork extends twaver.network.Network {
		public static const ElementType:String = "TYPE";
		
		/**
		 * 右键菜单
		 */
//		private var _rightMenu:Menu; 
		private var  _menuXMLList:XMLList;
		private var _selectElement:Element;
		private var _mouseMoveElement:Element;
//		private var elementMenu:ElementMenu;
		private var _menuCav:Canvas;
		
		public function BaseNetwork(elementBox:ElementBox=null) {
			super(elementBox);
			rightClick();
		}
		
		private function rightClick():void{
			this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMovehandler);
			initNetworkContextMenu();
		}
		
		private function initNetworkContextMenu():void{
//			addEventListener(AdvancedMouseEvent.RIGHT_MOUSE_DOWN, onMenuSelectedHandler);
		}
		
		protected function mouseMovehandler(e:MouseEvent):void{
			this.mouseMoveElement = this.getElementByMouseEvent(e) as Element;
			
//			if(null != mouseMoveElement && mouseMoveElement.name ==="黄山"){
//				this.editLineColor = 0x000000;
//			}else{
//				this.editLineColor = 0x123456;
//			}
		}
		
//		protected function onMenuSelectedHandler(event:AdvancedMouseEvent):void {
//			this.mouseMoveElement = this.getElementByMouseEvent(event) as Element;
//         selectionModel.setSelection(mouseMoveElement);
//			elementMenu.menu.removeEventListener(MenuEvent.ITEM_CLICK, onMenuItemClick);
//			flexContextMenu = elementMenu.menu;
//			
//			elementMenu.selectedItems = [this.mouseMoveElement];
//			elementMenu.menu.addEventListener(MenuEvent.ITEM_CLICK, onMenuItemClick);
//		}
		
//		private function onMenuItemClick(e:MenuEvent):void{
//			var item:MenuItem = e.item as MenuItem;
//			var param:* = item.data;
//			 if(null != param){
//				var eventName:String = param.eventName;
//				var data:Object = {
//					element: elementMenu.selectedItems[0],
//					network: this,
//					data:param
//				}
//				//派发右键事件
//				this.dispatchEvent(new NetworkEvent(eventName,data));
//			 }	
//		}
		
      /**
		 * 右键菜单的数据
		 */
		public function get menuXMLList():XMLList {
			return _menuXMLList;
		}
		
		/**
		 * @private
		 */
		public function set menuXMLList(value:XMLList):void {
			_menuXMLList = value;
		}
		
		/**
		 * 右键选中时的element
		 */
		public function get selectElement():Element {
			return _selectElement;
		}
		
		/**
		 * @private
		 */
		public function set selectElement(value:Element):void {
			_selectElement = value;
		}

		public function get mouseMoveElement():Element {
			return _mouseMoveElement;
		}

		public function set mouseMoveElement(value:Element):void {
			_mouseMoveElement = value;
		}
		
		override protected function createChildren():void {
			super.createChildren();
			
			if (!_menuCav) {
				_menuCav = new Canvas();
				_menuCav.visible = false;
				_menuCav.includeInLayout = false;
//				buildMenu(_menuCav);
				this.addChild(_menuCav);
			}
		}
		
//		protected function buildMenu(container:Container):void {
//			elementMenu = new ElementMenu();
//			elementMenu.network = this;
//			container.addChild(elementMenu);
//			flexContextMenu = elementMenu.menu;
//		}
	}
}